package com.empty.oredermenu.activity

import android.os.Bundle
import android.util.Log
import android.view.View
import android.webkit.WebView
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.empty.oredermenu.R
import com.empty.oredermenu.base.OrderMenuBaseActivity
import com.empty.oredermenu.javabeen.MenuListAdapterBeen
import com.empty.oredermenu.utils.UrlAllUtils

/**
 *  菜谱详情显示
 */
class MenuDetailActivity : OrderMenuBaseActivity() {


    var title_menudetali : TextView ? = null
    var food_menu : TextView ? = null
    var key_menu : TextView ? = null
    var detail_menu : TextView ? = null
    var detail_msg : TextView ? = null
    var detail_imgelist :ImageView? = null

    var web_orderdetali :WebView? = null

    var listbeen : MenuListAdapterBeen? = null
    var msg:String? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        toolsUtils!!.BuildColor(window, this, R.drawable.side_nav_bar)
        setContentView(R.layout.activity_menu_detail)
        baseInitView()
        layout_title!!.text = "菜谱详细"
        viewinit()
        val inten = intent
        if (inten != null){
            listbeen = inten.getSerializableExtra("listbeen") as MenuListAdapterBeen?
        }
        if (listbeen != null){
            title_menudetali!!.text = listbeen!!.name
            food_menu!!.text = "相关食物：\n"+listbeen!!.food
            key_menu!!.text = "关键词：\n"+listbeen!!.keywords
            detail_menu!!.text = "简介：\n"+listbeen!!.description

            Glide.with(this).
                    load(UrlAllUtils.URL_IMAGE+listbeen!!.img).
                    asBitmap().
                    placeholder(R.mipmap.mvr).
                    into(detail_imgelist)

            if (!listbeen!!.msg.equals("")){
                detail_msg!!.visibility = View.VISIBLE
                web_orderdetali!!.visibility  = View.VISIBLE

//                detail_msg!!.text = "详细：\n"+listbeen!!.msg
                web_setUpdata(listbeen!!.msg!!)
            }
        }

    }

    fun web_setUpdata(msgweb :String){
        // 加载html数据
        val sb = StringBuilder()
        sb.append("<html><body>")
        sb.append(msgweb)
        sb.append("</body></html>")
        web_orderdetali!!.loadDataWithBaseURL("", sb.toString(), "text/html",
                "UTF-8", "")
    }

    fun viewinit(){
        title_menudetali = findViewById(R.id.title_menudetali) as TextView
        food_menu = findViewById(R.id.food_menu) as TextView
        key_menu = findViewById(R.id.key_menu) as TextView
        detail_menu = findViewById(R.id.detail_menu) as TextView
        detail_msg = findViewById(R.id.detail_msg) as TextView
        detail_imgelist = findViewById(R.id.detail_imgelist) as ImageView
        web_orderdetali = findViewById(R.id.web_orderdetali) as WebView
    }


}
